package com.example.activemq.service;

import lombok.extern.slf4j.Slf4j;
import org.apache.activemq.Message;
import org.springframework.core.annotation.Order;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Service;

import javax.jms.JMSException;
import javax.jms.TextMessage;

@Service
@Slf4j
public class ConsumerService {

    @JmsListener(destination = "activeMQTopic", containerFactory = "jmsTopicListenerContainerFactory")
    public void receiveMessage(final Message message) throws JMSException {
        log.info("接收主题消息:{}", message);
        if (message instanceof TextMessage) {
            TextMessage textMessage = (TextMessage)message;
            String messageData = textMessage.getText();
            System.out.println(messageData);

        }
    }
    @JmsListener(destination = "activeMQQueue", containerFactory = "jmsQueueListenerContainerFactory")
    public void receiveQueueMessage(final Message message) throws JMSException {
        log.info("接收队列消息:{}", message);
        if (message instanceof TextMessage) {
            TextMessage textMessage = (TextMessage)message;
            String messageData = textMessage.getText();
            System.out.println(messageData);

        }
    }


}
